package com.lujieni.springbootcaffeine.runner;

import com.lujieni.springbootcaffeine.cache.DefaultTTLCaffeineCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 1.run方法的阻塞不会影响到springboot对外提供服务
 * 2.执行run方法的是main线程
 */
@Component
public class WarmDataRunner implements ApplicationRunner {

    @Autowired
    List<DefaultTTLCaffeineCache> list;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        for (DefaultTTLCaffeineCache caffeine: list) {
            caffeine.warmData();
        }
        System.out.println("warm data done");
    }
}
